package com.idea.zd.sys.train.thread;

/**
 * 实现runnable接口，重写run方法
 */
public class RunnableTest implements Runnable{

    private int i;

    @Override
    public void run() {

        for(;i<10;i++){

            //当线程实现runnable接口时，如果想获取当前线程，只以用Thread.currentThread方法
            System.out.println(Thread.currentThread().getName()+ " :"+i);
        }
    }

    public static void main(String [] args){
        RunnableTest runnableTest = new RunnableTest();
        Thread thread =new Thread(runnableTest,"1新线程"+"");

        for(int i = 0; i < 100; i++){

            //当线程处于新建、运行、阻塞 isAlive返回true
            System.out.println("0isAlive："+thread.isAlive());
            if( i == 20){
                thread.start();
                System.out.println("1isAlive："+thread.isAlive());
            }


            if(i == 21){
                System.out.println("2isAlive："+thread.isAlive());
            }


            System.out.println("3isAlive："+thread.isAlive());
        }
    }
}
